import api from '../api.js';

const getListAsync = async (data) => {
  return await api.postWithToken({
    command: 'I_User_GetUsers',
    data
  });
};

const addAsync = async (data) => {
  return await api.postWithToken({
    command: 'I_User_New',
    data
  });
};

const editAsync = async (data) => {
  return await api.postWithToken({
    command: 'I_User_Modify',
    data
  });
};

const deleteAsync = async (id) => {
  return await api.postWithToken({
    command: 'I_User_Delete',
    data: {
      user_id: id
    }
  });
};

const getRolesAsync = async (user_id) => {
  return await api.postWithToken({
    command: 'I_User_GetRoles',
    data: {
      user_id: user_id,
      page_size: 999,
      page_index: 1
    }
  });
};

const getPowerAsync = async (user_id) => {
  return await api.postWithToken({
    command: 'I_User_GetPowers',
    data: {
      user_id: user_id,
      page_size: 999,
      page_index: 1
    }
  });
};

const setRolesAsync = async (user_id, role_ids) => {
  return await api.postWithToken({
    command: 'I_User_SetRoles',
    data: {
      user_id: user_id,
      roles: role_ids,
    }
  });
};

const changePassWordAsync = async (data) => {
  return await api.postWithToken({
    command: 'I_User_ChangePassword',
    data
  });
};




export default {
  getListAsync,
  addAsync,
  editAsync,
  deleteAsync,
  getRolesAsync,
  setRolesAsync,
  getPowerAsync,
  changePassWordAsync
}